//
//  HomeViewController.m
//  YTwallet
//
//  Created by hadrlog on 2019/2/22.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "HomeViewController.h"
#import "ViewController.h"
#import "HomeView.h"
#import "HomeCollectionViewCell.h"
//轮播图
#import "SDCycleScrollView.h"
#import "UIImageView+WebCache.h"
//右上角菜单
#import "OYRPopOption.h"
//我的额度
#import "LimitViewController.h"
//我的费率
#import "RateViewController.h"
//刷卡收款
#import "CollectViewController.h"
//信用卡收款
#import "CreditViewController.h"
//消息列表
#import "MessageListViewController.h"
//账单查询
#import "BillSelectViewController.h"
//登录
#import "LoginViewController.h"
//nav
#import "NavigateViewController.h"
//提示实名弹窗
#import "ReminderAutonymView.h"
//提示开启指纹手势弹窗
#import "ReminderFingerOrGesterView.h"
//实名认证页面
#import "AuthenViewController.h"
//高级认证页面
#import "AdvancedIdentifyViewController.h"
//开启手势或指纹解锁
#import "SettingViewController.h"

//获取金融服务列表
#import "HomeModelPack.h"
//webView展示
#import "HomeWebViewController.h"
//金融服务更多
#import "MoreAdViewController.h"

#import <Masonry.h>



@interface HomeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,SDCycleScrollViewDelegate>
@property(nonatomic,strong)HomeView *hv;

@property(nonatomic,strong)UICollectionView *financialServiceCollectionView;

@property(nonatomic,strong)NSMutableArray *titleArray;
@property(nonatomic,strong)NSMutableArray *imageArray;
@property(nonatomic,strong)NSMutableArray *pathArray;
@property(nonatomic,strong)NSMutableArray *recordArray;
@property(nonatomic,strong)NSMutableArray *slideArray;


//在小屏上可以滑动
@property(nonatomic,strong) UIScrollView *scrollView;

@property(nonatomic,strong)ReminderAutonymView *rv;
@property(nonatomic,strong)ReminderFingerOrGesterView *reminderfOrgView;




@end

@implementation HomeViewController
{
    NSArray *_imagesURLStrings;
    SDCycleScrollView *_customCellScrollViewDemo;
}


#pragma mark ---------------------------
#pragma mark -懒加载

-(NSMutableArray *)titleArray
{
    if (_titleArray == nil) {
        _titleArray = [NSMutableArray array];
    }
    return _titleArray;
}
-(NSMutableArray *)imageArray
{
    if (_imageArray == nil) {
        _imageArray = [NSMutableArray array];
    }
    return _imageArray;
}
-(NSMutableArray *)pathArray
{
    if (_pathArray == nil) {
        _pathArray = [NSMutableArray array];
    }
    return _pathArray;
}
-(NSMutableArray *)recordArray
{
    if (_recordArray == nil) {
        _recordArray = [NSMutableArray array];
    }
    return _recordArray;
}
-(NSMutableArray *)slideArray
{
    if (_slideArray == nil) {
        _slideArray = [NSMutableArray array];
    }
    return _slideArray;
}



#pragma mark 初始化
-(void)loadView{
    [super loadView];
    self.hv = [[HomeView alloc] initWithFrame:self.view.bounds];
//    self.view = self.hv;
}

//认证框
-(void)openRemindViewWithTips:(NSString *)Tips toAuthBtnTitle:(NSString *)toAuthBtnTitle
{
    //未实名弹出提示框
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    self.rv = [[ReminderAutonymView alloc] initWithFrame:keyWindow.bounds];
    [keyWindow addSubview:self.rv];
    
    self.rv.tipsLab.text = Tips;
    [self.rv.toAuthenBtn setTitle:toAuthBtnTitle forState:(UIControlStateNormal)];
    
    self.rv.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.rv addGestureRecognizer:tap];
    //点击退出实名弹窗
    [self.rv.nextTimeReminderBtn addTarget:self action:@selector(nextTimeReminderBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.rv.toAuthenBtn addTarget:self action:@selector(toAuthenBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}
//开启手势指纹框
-(void)openFingerprintOrGesture
{
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    self.reminderfOrgView = [[ReminderFingerOrGesterView alloc] initWithFrame:keyWindow.bounds];
    [keyWindow addSubview:self.reminderfOrgView];
    
    self.reminderfOrgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reminderfOrgViewtapAction:)];
    [self.reminderfOrgView addGestureRecognizer:tap];
    //点击开启手势解锁
    [self.reminderfOrgView.openGestureBtn addTarget:self action:@selector(openGestureBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    //点击开启指纹解锁
    [self.reminderfOrgView.openFingerprintBtn addTarget:self action:@selector(openGestureBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    //点击不在显示
    [self.reminderfOrgView.noReminderBtn addTarget:self action:@selector(noReminderBtnAction)
                                  forControlEvents:(UIControlEventTouchUpInside)];
    
}
-(void)openGestureBtnAction
{
    [self.reminderfOrgView removeFromSuperview];
    SettingViewController *settingVC = [[SettingViewController alloc] init];
    [self.navigationController pushViewController:settingVC animated:YES];
}
-(void)noReminderBtnAction
{
    [self.reminderfOrgView removeFromSuperview];
    //记录状态不在展示
    
}

-(void)toAuthenBtnAction:(UIButton *)btn
{
    [self.rv removeFromSuperview];
    if ([@"去实名认证" isEqualToString:btn.titleLabel.text]) {
        AuthenViewController *authenVC = [[AuthenViewController alloc] init];
        [self.navigationController pushViewController:authenVC animated:YES];
    }else if ([@"去高级证" isEqualToString:btn.titleLabel.text])
    {
        AdvancedIdentifyViewController *advanceVC = [[AdvancedIdentifyViewController alloc] init];
        [self.navigationController pushViewController:advanceVC animated:YES];
    }
    
    
    
}

-(void)nextTimeReminderBtnAction
{
    [self.rv removeFromSuperview];
}

//退出实名认证框
-(void)tapAction:(UITapGestureRecognizer*)gap
{
    CGPoint point = [gap locationInView:self.rv];
    point = [self.rv.topView.layer convertPoint:point fromLayer:self.rv.layer];
    if (![self.rv.topView.layer containsPoint:point]) {
        [self.rv removeFromSuperview];
    }
}
//退出手势指纹框
-(void)reminderfOrgViewtapAction:(UITapGestureRecognizer*)gap
{
    CGPoint point = [gap locationInView:self.rv];
    point = [self.reminderfOrgView.topView.layer convertPoint:point fromLayer:self.reminderfOrgView.layer];
    if (![self.reminderfOrgView.topView.layer containsPoint:point]) {
        [self.reminderfOrgView removeFromSuperview];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //右上角更多
    [self createRightBtn];
    //创建collectionView(金融服务)
    [self setUpCollectionView];
    //轮播图(先加载本地数据)
//    [self carousel];
    //金融服务(先加载本地数据)
    [self localData];
    //小屏可滑动
    [self slide];
    //跳转刷卡收款
    self.hv.swipeCardImv.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ToswipeCard)];
    [self.hv.swipeCardImv addGestureRecognizer:tap];
    //跳转到信用卡收款
    self.hv.creditCardImv.userInteractionEnabled = YES;
    UITapGestureRecognizer *creditCardTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(creditCardTapAction)];
    [self.hv.creditCardImv addGestureRecognizer:creditCardTap];
    //跳转到消息列表
    UITapGestureRecognizer *messageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(messageTapAction)];
    [self.hv.messageView addGestureRecognizer:messageTap];
    //获取金融服务信息
    [self getFinancialService];
    if ([AppTools isLogin]) {
        //弹出弹窗(实名认证、开启指纹等)
        /*
         static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
         
         });
         */
        
        [self popView];
    }
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //判断消息小红点是否显示
    if ([@"0" isEqualToString:[AppTools shareInstance].msgInfo.status]) {
        self.hv.pointView.hidden = NO;
    }else if([@"1" isEqualToString:[AppTools shareInstance].msgInfo.status])
    {
        self.hv.pointView.hidden = YES;
    }
    
}
-(void)popView
{
        if ([AppTools isOpenedFingerprint] || [AppTools isIsOpenedGesture]) {  //开启了指纹或者手势
            if ([AppTools checkLoginResponseAllState] == ETNOAutonym) {                       //未实名
                //实名认证框(基础认证)
//                [self openRemindView];
            }
        }else
        {
            
            //开启指纹或者手势框
            [self openFingerprintOrGesture];
        }

 
}
-(void)getFinancialService
{
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/home/homePage"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOSTNOTips:url Parameters:nil HttpBody:nil SuccessHandler:^(id responseObject) {
        
        
        //存储首页返回的信息  没有网络或者还没加载出来先显示本地存储的数据
        [AppTools setFinancialServiceData:responseObject];
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self dealHomeResponse:responseObject];
            });
        }else
        {
            //加载本地数据
            
        }
        
        
        
    } FailedHandler:^(NSError *error) {
        //加载本地数据
        
    }];

}
/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    NSString *path = [self.slideArray[index] pagePath];
    NSString *name =[self.slideArray[index] businessName];
    HomeWebViewController *homeWebVC = [[HomeWebViewController alloc] init];
    homeWebVC.titleStr = name;
    homeWebVC.urlStr = path;
    [self.navigationController pushViewController:homeWebVC animated:YES];
}


-(void)localData
{
    NSData *data = [AppTools getFinancialServiceData];
    [self dealHomeResponse:data];
}

-(void)dealHomeResponse:(id)responseObject
{
    HomeResponse *homeResponse = [HomeResponse mj_objectWithKeyValues:responseObject];
    //加载跑马灯文字  未登录取首页返回的且不显示已读未读    登录成功取登录返回的消息
    if ([AppTools isLogin]) {
        self.hv.contentLabel.text = [AppTools shareInstance].msgInfo.content;
        self.hv.timeLab.text = [AppTools shareInstance].msgInfo.createTime;
        if (self.hv.contentLabel.text.length == 0) {
            self.hv.pointView.hidden = YES;
        }
        
        
        if ([@"0" isEqualToString:[AppTools shareInstance].msgInfo.status]) {
            self.hv.pointView.hidden = NO;
        }else if([@"1" isEqualToString:[AppTools shareInstance].msgInfo.status])
        {
            self.hv.pointView.hidden = YES;
        }
    }else
    {
        self.hv.contentLabel.text = homeResponse.response.noticeInfoMap.content;
        self.hv.timeLab.text = homeResponse.response.noticeInfoMap.updateTime;
        self.hv.pointView.hidden = YES;
    }
    
    
    
    
    
    //轮播图数据
    if (homeResponse.response.slideShowList.count == 0) {
        //加载本地数据
    }else
    {
        [self.slideArray removeAllObjects];
        for (Slide *slide in homeResponse.response.slideShowList) {
            [self.slideArray addObject:slide];
        }
        //轮播图
        [self carousel];
    }
    
    //金融服务数据
    if (homeResponse.response.expandConfigInfo.count == 0) {
        //加载本地数据
    }else
    {
        [self.recordArray removeAllObjects];
        for (HomeRecord *record in homeResponse.response.expandConfigInfo) {
            [self.recordArray addObject:record];
        }
        //更新tableView
        [self.financialServiceCollectionView reloadData];
    }
    //存储手机号
    [AppTools setPhoneNum:homeResponse.response.serviceHotline];
}

-(void)creditCardTapAction
{
    //检查是否登录
    if (![AppTools isLogin]) { // 未登录
        NSLog(@"未登录");
        //跳转到登录页面
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        NavigateViewController *nav = [[NavigateViewController alloc] initWithRootViewController:loginVC];
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }else if ([AppTools checkLoginResponseAllState] == ETNOAutonym)  //已登录未实名
    {
        NSLog(@"已登录未实名");
        //实名认证框(基础认证)
        [self openRemindViewWithTips:@"您还未实名认证" toAuthBtnTitle:@"去实名认证"];

    }else if([AppTools checkLoginResponseAllState] == ETBasicAuthentication ||
             [AppTools checkLoginResponseAllState] == ETAdvancedAuthentication)
    {
        CreditViewController *creditVC = [[CreditViewController alloc] init];
        [self.navigationController pushViewController:creditVC animated:YES];
    }
}

-(void)messageTapAction
{
    //未登录不能跳转消息详情
    if ([AppTools isLogin]) {
        MessageListViewController *messageListVC = [[MessageListViewController alloc] init];
        [self.navigationController pushViewController:messageListVC animated:YES];
    }else
    {
        [self showFailedResultTips:@"请先登录" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
    }
    
    
}
-(void)ToswipeCard
{
    
    //跳转账单查询
    
    
    if (![AppTools isLogin]) { // 未登录
        NSLog(@"未登录");
        //跳转到登录页面
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        NavigateViewController *nav = [[NavigateViewController alloc] initWithRootViewController:loginVC];
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }else if ([AppTools checkLoginResponseAllState] == ETNOAutonym)  //已登录未实名
    {
        [self showFailedResultTips:@"请先实名认证" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
    }else if([AppTools checkLoginResponseAllState] == ETBasicAuthentication)
    {
        BillSelectViewController *billVC = [[BillSelectViewController alloc] init];
        [self.navigationController pushViewController:billVC animated:YES];
    }
    

    
    /*
    //检查是否登录
    if (![AppTools isLogin]) { // 未登录
        NSLog(@"未登录");
        //跳转到登录页面
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        NavigateViewController *nav = [[NavigateViewController alloc] initWithRootViewController:loginVC];
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }else if ([AppTools checkLoginResponseAllState] == ETNOAutonym)  //已登录未实名
    {
        [self showFailedResultTips:@"请先实名认证" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
    }else if([AppTools checkLoginResponseAllState] == ETBasicAuthentication)
    {
        CollectViewController *collecVC = [[CollectViewController alloc] init];
        [self.navigationController pushViewController:collecVC animated:YES];
        
    }else if([AppTools checkLoginResponseAllState] == ETAdvancedAuthentication)
    {
        CollectViewController *collecVC = [[CollectViewController alloc] init];
        [self.navigationController pushViewController:collecVC animated:YES];
    }
     */
    
    
    
    
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if(CGRectGetMaxY(self.hv.financialServiceView.frame) + 49 >= self.view.bounds.size.height){
        self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width,CGRectGetMaxY(self.hv.financialServiceView.frame) + 64 + 49);
    }else{
        self.scrollView.contentSize = self.view.frame.size;
    }
}
-(void)slide
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.scrollView.backgroundColor  = [UIColor colorWithRed:242 / 255.0 green:244 / 255.0 blue:246 / 255.0 alpha:1.0];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.hv];
    
}

-(void)createRightBtn
{
    UIButton *rightBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    rightBtn.tag = 10000;
    rightBtn.frame = CGRectMake(0, 0, 40, 20);
    [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [rightBtn setImage:[UIImage imageNamed:@"nav_icon_more"] forState:(UIControlStateNormal)];
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    
    
}


-(void)carousel
{
    if (self.slideArray.count == 0) {
        //本地加载
         NSArray *imageNames = @[@"home_banner",
         @"home_banner",
         @"home_banner",
         @"home_banner"
         ];
         
         CGFloat w = self.view.bounds.size.width;
         UIScrollView *demoContainerView = [[UIScrollView alloc] initWithFrame:CGRectMake(15, 10, self.view.frame.size.width - 30, 90)];
        demoContainerView.layer.cornerRadius = 4;
        demoContainerView.layer.masksToBounds = YES;
         demoContainerView.contentSize = CGSizeMake(self.view.frame.size.width, 90);
//         demoContainerView.layer.cornerRadius = 4;
         [self.hv.carouselview addSubview:demoContainerView];
         SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, w, 90) shouldInfiniteLoop:YES imageNamesGroup:imageNames];
         cycleScrollView.delegate = self;
         cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
         cycleScrollView.pageDotImage = [UIImage imageNamed:@"pageDo"];
         cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"pageCurrent"];
        
         [demoContainerView addSubview:cycleScrollView];
    }else
    {
        // 情景二：采用网络图片实现
        NSMutableArray *array = [[NSMutableArray alloc] init];
        for (int i = 0; i < self.slideArray.count; i++) {
            [array addObject:[self.slideArray[i] imagePath]];
        }
        NSArray *imagesURLStrings = [array copy];
        _imagesURLStrings = imagesURLStrings;
        // 网络加载 --- 创建带标题的图片轮播器
        UIScrollView *demoContainerView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 10, self.view.frame.size.width - 20, 90)];
        demoContainerView.contentSize = CGSizeMake((self.view.frame.size.width-20)*imagesURLStrings.count, 90);
        demoContainerView.layer.cornerRadius = 4;
        [self.hv.carouselview addSubview:demoContainerView];
        
        SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ETScreenW, 90) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        
        cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        cycleScrollView2.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        cycleScrollView2.pageDotImage = [UIImage imageNamed:@"pageDo"];
        cycleScrollView2.currentPageDotImage = [UIImage imageNamed:@"pageCurrent"];
        [demoContainerView addSubview:cycleScrollView2];
        
        cycleScrollView2.imageURLStringsGroup = imagesURLStrings;
    }
    
    
    
    
}
-(void)setUpCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat with = (self.view.frame.size.width - 30) / 4.0;
    CGFloat higth = with;
    layout.itemSize = CGSizeMake(with,higth);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
    self.financialServiceCollectionView = [[UICollectionView alloc] initWithFrame:(CGRectMake(0, 44, self.view.frame.size.width, 200)) collectionViewLayout:layout];
    [self.financialServiceCollectionView registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.financialServiceCollectionView.backgroundColor = [UIColor whiteColor];
    self.financialServiceCollectionView.delegate = self;
    self.financialServiceCollectionView.dataSource = self;
    self.financialServiceCollectionView.scrollEnabled = NO;
    [self.hv.financialServiceView addSubview:self.financialServiceCollectionView];
}

#pragma mark ---------------------------
#pragma mark -UICollectionView
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.recordArray.count >= 8) {
        return 8;
    }else
    {
       return self.recordArray.count;
    }
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (indexPath.row == 7) {
        cell.titleLab.text = @"更多";
        cell.imageView.image = [UIImage imageNamed:@"home_icon_more"];
    }else
    {
        HomeRecord *recoed = self.recordArray[indexPath.row];
        cell.titleLab.text = recoed.businessName;
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:recoed.imagePath] placeholderImage:[UIImage imageNamed:@"home_icon__loading"]];
        cell.titleLab.text = recoed.businessName;
    }
    
    return cell;
}

-(void)rightBtnAction:(UIButton *)optionButton
{
    NSLog(@"点击右上角更多");
    // 注意：由convertRect: toView 获取到屏幕上该控件的绝对位置。
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    CGRect frame = [optionButton convertRect:optionButton.bounds toView:window];
    
    
    OYRPopOption *s = [[OYRPopOption alloc] initWithFrame:CGRectMake(0, 0, ETScreenW, ETScreenH)];
    s.option_optionContents = @[@"我的账单", @"我的额度", @"我的费率", @"联系我们"];
    s.option_optionImages = @[@"more_icon_order",@"more_icon_ edu",@"more_icon_ feilv",@"more_icon_ contactus"];
    
    [[s option_setupPopOption:^(NSInteger index, NSString *content) {
       
        if (index != 3) {
            //检查是否登录
            if (![AppTools isLogin]) { // 未登录
                NSLog(@"未登录");
                //跳转到登录页面
                LoginViewController *loginVC = [[LoginViewController alloc] init];
                NavigateViewController *nav = [[NavigateViewController alloc] initWithRootViewController:loginVC];
                [self presentViewController:nav animated:YES completion:nil];
                return;
            }
        }
        
        
        switch (index) {
            case 0:
            {
                NSLog(@"我的账单");
                BillSelectViewController *billVC = [[BillSelectViewController alloc] init];
                [self.navigationController pushViewController:billVC animated:YES];
            }
                break;
            case 1:
            {
                NSLog(@"我的额度");
                [self showFailedResultTips:ETNODisparkStr animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
                /*
                LimitViewController *limitVC = [[LimitViewController alloc] init];
                [self.navigationController pushViewController:limitVC animated:YES];
                 */
            }
                break;
            case 2:
            {
                NSLog(@"我的费率");
                [self showFailedResultTips:ETNODisparkStr animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
                /*
                RateViewController *rateVC = [[RateViewController alloc] init];
                [self.navigationController pushViewController:rateVC animated:YES];
                 */
            }
                break;
            case 3:
            {
                NSLog(@"联系我们");
                [self call];
            }
                break;
                
            default:NSLog(@"未选择");
                break;
        }
        
    } whichFrame:frame animate:YES] option_show];
    
    //更新小箭头View  与三个点中间的对齐
    [s.cornerImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(s.backgroundView.mas_top);
        make.centerX.equalTo(optionButton);
        make.width.mas_equalTo(10);
        make.height.mas_equalTo(6);
    }];
    
}
-(void)runnext{
    ViewController *vc = [[ViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
//调用系统打电话
-(void)call
{
    if ([AppTools getPhoneNum].length == 0) {
        [self showFailedResultTips:@"未获取到客服电话" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
    }else
    {
        NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", [AppTools getPhoneNum]];
        
        NSComparisonResult compare = [[UIDevice currentDevice].systemVersion compare:@"10.0"];
        
        if (compare == NSOrderedDescending || compare == NSOrderedSame) {
            
            /// 大于等于10.0系统使用此openURL方法
            
            if (@available(iOS 10.0, *)) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
            } else {
                // Fallback on earlier versions
            }
            
        } else {
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
            
        }
    }
    
    
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"点击金融服务item");
    if (indexPath.row == 7) {
        
        //点击更多  删除“更多”
        for (HomeRecord *record in self.recordArray) {
            if ([record.businessName isEqualToString:@"更多"]) {
                [self.recordArray removeObject:record];
            }
        }
        
        
        
        
        
        MoreAdViewController *MoreAdVC = [[MoreAdViewController alloc] init];
        MoreAdVC.recordArray = self.recordArray;
        [self.navigationController pushViewController:MoreAdVC animated:YES];
    }else
    {
        NSString *webViewPathStr = [self.recordArray[indexPath.row] pagePath];
        NSLog(@"%@",webViewPathStr);
        NSString *webViewTitleStr = [self.recordArray[indexPath.row] businessName];
        NSLog(@"%@",webViewTitleStr);
        HomeWebViewController *homeWebVC = [[HomeWebViewController alloc] init];
        homeWebVC.titleStr = webViewTitleStr;
        homeWebVC.urlStr = webViewPathStr;
        [self.navigationController pushViewController:homeWebVC animated:YES];
    }
}

@end
